package com.yanggu.scala.chapater18.viewbounds

object ViewBoundsDemo02 {

  def main(args: Array[String]): Unit = {
    val p1 = new Person18("tom", 10)
    val p2 = new Person18("jack", 20)
    val value = new CompareComm18(p1, p2)
    println(value.getter)
  }

}
/*
说明: 使用视图界定的方式，比较两个Person对象的年龄大小。
*/
class Person18(val name: String, val age: Int) extends Ordered[Person18] {

  override def compare(that: Person18) = this.age - that.age

  override def toString = this.name + "\t" + this.age

}

class CompareComm18[T <% Ordered[T]](obj1: T, obj2: T) {

  //这里使用的是操作符重载
  def getter = if (obj1 > obj2) obj1 else obj2

  def geatter2 = if (obj1.compareTo(obj2) > 0) obj1 else obj2

}
